'use strict'
const path = require('path')
const defaultSettings = require('./src/settings.js')

const webpack = require('webpack')


function resolve(dir) {
  return path.join(__dirname, dir)
}

const name = defaultSettings.title || 'vue Element Admin' // page title

// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run
// You can change the port by the following method:
// port = 9527 npm run dev OR npm run dev --port = 9527
const port = process.env.port || process.env.npm_config_port || 9538 // dev port





// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
  /**
   * You will need to set publicPath if you plan to deploy your site under a sub path,
   * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
   * then publicPath should be set to "/bar/".
   * In most cases please use '/' !!!
   * Detail: https://cli.vuejs.org/config/#publicpath
   */
  publicPath: './',
  outputDir: 'dist',
  assetsDir: 'static',
  lintOnSave: process.env.NODE_ENV === 'development',
  productionSourceMap: false,
  // devServer: {
  //   port: port,
  //   open: true,
  //   overlay: {
  //     warnings: false,
  //     errors: true
  //   },
  //   before: require('./mock/mock-server.js')
  // },
  devServer: {
    host: 'localhost',
    port: port,
    open: true,
    proxy: {
      // '/': {
      //   target: 'https://lock.pacargle.com',// 要跨域的域名 // 【相同的 协议/ip/端口 只需要配置一条】
      //   changeOrigin: true, // 是否开启跨域
      //   seture:false
      // },
      '/vehicleMap': {
        target: 'https://bs.pacargle.com:221',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/vehicleMap': ''
        }
      }, 
      '/cycleMap': {
        target: 'https://lock.pacargle.com:667',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/cycleMap': ''
        }
      },
      '/cyclebike': {
        target: 'https://lock.pacargle.com',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/cyclebike': ''
        }
      },
      '/run': {
        target: 'https://bs.pacargle.com:221',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/run': ''
        }
      },
      '/lcchargerlog/exportChargerLog': {
        target: 'https://bs.pacargle.com:221',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/lcchargerlog/exportChargerLog': '/lcchargerlog/exportChargerLog'
        }
      }, 
      '/lcchargerlog/exportIncome': {
        target: 'https://bs.pacargle.com:221',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/lcchargerlog/exportIncome': '/lcchargerlog/exportIncome'
        }
      }, 

      '/lcuser/exportUsers': {
        target: 'https://bs.pacargle.com:221',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/lcuser/exportUsers': '/lcuser/exportUsers'
        }
      },
      
      '/lcebchargerlog/exportLcEbChargerLogByCond': {
        target: 'https://bs.pacargle.com:221',
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          '^/lcebchargerlog/exportLcEbChargerLogByCond': '/lcebchargerlog/exportLcEbChargerLogByCond'
        }
      }, 






      

    }
    //   '/customer': {
    //     target: 'https://bs.pacargle.com:221',// 要跨域的域名 // 【相同的 协议/ip/端口 只需要配置一条】
    //     changeOrigin: true, // 是否开启跨域
    //     pathRewrite: {   //重写路径
    //       '^/customer': ''   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //     }
    //   },

    //   '/parkfield': {
    //     target: 'https://bs.pacargle.com:221',// 要跨域的域名 // 【相同的 协议/ip/端口 只需要配置一条】
    //     changeOrigin: true, // 是否开启跨域
    //     pathRewrite: {   //重写路径
    //       '^/parkfield': ''   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //     }
    //   },

    //   '/order': {
    //     target: 'https://bs.pacargle.com:221',// 要跨域的域名 // 【相同的 协议/ip/端口 只需要配置一条】
    //     changeOrigin: true, // 是否开启跨域
    //     pathRewrite: {   //重写路径
    //       '^/order': ''   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //     }
    //   },

    //   '/device': {
    //     target: 'https://lock.pacargle.com',// 要跨域的域名 // 【相同的 协议/ip/端口 只需要配置一条】
    //     changeOrigin: true, // 是否开启跨域
    //     pathRewrite: {   //重写路径
    //       '^/device': '/device'   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //     }
    //   },

    //   '/fund': {
    //     target: 'https://bs.pacargle.com:221',
    //     secure: false,
    //     changeOrigin: true,
    //     pathRewrite: {
    //     '^/fund': ''
    //     }
    //   },

    //   '/login': {
    //     target: 'https://bs.pacargle.com:221',
    //     secure: false,
    //     changeOrigin: true,
    //     pathRewrite: {
    //     '^/login': ''
    //     }
    //   },


    //   '/lclock/getPriceBylock': {
    //     target: 'https://lock.pacargle.com',
    //     secure: false,
    //     changeOrigin: true,
    //     pathRewrite: {
    //     '^/lclock/getPriceBylock': '/lclock/getPriceBylock'
    //     }
    //   },
    // }



    
    // proxy: {     
    //         '/device': {
    //             target: 'https://bs.pacargle.com:221',// 要跨域的域名 // 【相同的 协议/ip/端口 只需要配置一条】
    //             changeOrigin: true, // 是否开启跨域
    //             pathRewrite: {   //重写路径
    //               '^/device': '/device'   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //             }
    //           },
    //           '/lcmanager': {
    //             target: 'https://bs.pacargle.com:221',// 要跨域的域名
    //             changeOrigin: true, // 是否开启跨域
    //             pathRewrite: {   //重写路径
    //               '^/lcmanager': '/lcmanager'   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //             }
    //           },
    //           '/lcuser': {
    //             target: 'https://bs.pacargle.com:221',// 要跨域的域名
    //             changeOrigin: true, // 是否开启跨域
    //             pathRewrite: {   //重写路径
    //               '^/lcuser': '/lcuser'   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //             }
    //           },
    //           '/lcparkfield': {
    //             target: 'https://bs.pacargle.com:221',// 要跨域的域名
    //             changeOrigin: true, // 是否开启跨域
    //             pathRewrite: {   //重写路径
    //               '^/lcparkfield': '/lcparkfield'   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //             }
    //           },
    //           '/lcchargerlog': {
    //             target: 'https://bs.pacargle.com:221',// 要跨域的域名
    //             changeOrigin: true, // 是否开启跨域
    //             pathRewrite: {   //重写路径
    //               '^/lcchargerlog': '/lcchargerlog'   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //             }
    //           },
    //           // '/lclock': {
    //           //   target: 'https://bs.pacargle.com:221',// 要跨域的域名
    //           //   changeOrigin: true, // 是否开启跨域
    //           //   pathRewrite: {   //重写路径
    //           //     '^/lclock': '/lclock'   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //           //   }
    //           },
    //           '/lcmanager/login': {
    //             target: 'https://bs.pacargle.com:221',// 要跨域的域名
    //             changeOrigin: true, // 是否开启跨域
    //             pathRewrite: {   //重写路径
    //               '^/lcmanager/login': '/lcmanager/login'   // 这种接口配置出来     http://XX.XX.XX.XX:8083/api/login
    //             }
    //           }
    //         }
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.

    plugins:[
      new webpack.ProvidePlugin({
          $: 'jquery',
          jQuery: 'jquery'
      })
  ],
    name: name,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  },



  chainWebpack(config) {
    // it can improve the speed of the first screen, it is recommended to turn on preload
    // it can improve the speed of the first screen, it is recommended to turn on preload
    config.plugin('preload').tap(() => [
      {
        rel: 'preload',
        // to ignore runtime.js
        // https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
        fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
        include: 'initial'
      }
    ])

    // when there are many pages, it will cause too many meaningless requests
    config.plugins.delete('prefetch')

    // set svg-sprite-loader
    config.module
      .rule('svg')
      .exclude.add(resolve('src/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()

    config
      .when(process.env.NODE_ENV !== 'development',
        config => {
          config
            .plugin('ScriptExtHtmlWebpackPlugin')
            .after('html')
            .use('script-ext-html-webpack-plugin', [{
              // `runtime` must same as runtimeChunk name. default is `runtime`
              inline: /runtime\..*\.js$/
            }])
            .end()
          config
            .optimization.splitChunks({
              chunks: 'all',
              cacheGroups: {
                libs: {
                  name: 'chunk-libs',
                  test: /[\\/]node_modules[\\/]/,
                  priority: 10,
                  chunks: 'initial' // only package third parties that are initially dependent
                },
                elementUI: {
                  name: 'chunk-elementUI', // split elementUI into a single package
                  priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
                  test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
                },
                commons: {
                  name: 'chunk-commons',
                  test: resolve('src/components'), // can customize your rules
                  minChunks: 3, //  minimum common number
                  priority: 5,
                  reuseExistingChunk: true
                }
              }
            })
          // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
          config.optimization.runtimeChunk('single')
        }
      )
  }
}
